package com.xms.consumers.security;

import com.xms.sdk.event.EntityDeletedEvent;
import com.xms.security.service.dataauth.IPrincipalObjectAccessService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 实体删除后删除相关的数据授权
 * </p>
 *
 * @author migo
 * @since 2021/9/29
 */
@Service
public class RemovePOAOnEntityDeleted {
    private IPrincipalObjectAccessService _principalObjectAccessService;

    @Autowired
    public RemovePOAOnEntityDeleted(IPrincipalObjectAccessService principalObjectAccessService) {
        _principalObjectAccessService = principalObjectAccessService;
    }

    @Async
    @EventListener
    public void handleEvent(EntityDeletedEvent eventMessage) {
        _principalObjectAccessService.deleteByObjectId(eventMessage.EntityMetadata.getEntityid(), eventMessage.source.getIdValue());
    }
}
